
if not SYSPATH then return end
    
    -- __ADD_SEARCH_PATH__("res/sgpk/actor")
    -----------------------------------------
    --选择规则界面 必须继承ScrollView
    -----------------------------------------
    local zOrder    = 1000
    local function getOrder()
        zOrder = zOrder+1
        return zOrder
    end
    
    local model  = app.model("hall")
    local conf   = app.gamesUse("conf")
    
    local SIZE_W = 772
    local SIZE_H = 500					--默认1000

    local path = "common/"
    
    local TAG_PLAYER_NUM=10
    local TAG_JUSHU=30
    local TAG_RULE1=50
    local TAG_RULE2=60
    
    
    local TEXT_FONT=SYSFONT              --字体
    local TEXT_COLOR=cc.c3b(0,0,0)       --字体颜色
    
    local Start_X=140                    --标题位置
    local Start_Y=400                    --第一个item位置
    local TEMP_X=200                     --行间隔
    local TEMP_Y=100                     --列间隔
    local X1=80                          --第一个选择框位置
    local X2=120                         --第一个文字位置
    local MAX_NUM=2                      --每行最多排几个按钮  不能为1
    
    local M      = class("RuleView",function ()
        return   cc.Layer:create()
    end)
    
    local sgpk_model     = app.gamesUse("model")
    local hall_model     = app.model("hall")
    
    function M:ctor()
        self.PlayerNum=0
        self.jushuNum=0
        self.rule_result={}
        self:setContentSize(SIZE_W,SIZE_H)
        self:init()
    end
    
    function M:init()
        dump(hall_model.PlayerNumConf.get())
        dump(hall_model.DepletedConf.get())
        dump(hall_model.CurRule.get())
    
        local y=Start_Y
    
        -------------------------------------------------------------------------------人数
        local PlayerData=hall_model.PlayerNumConf.get()
    
        local Player_Lab=cc.Label:createWithSystemFont("人数:",TEXT_FONT, 30)
        Player_Lab:setColor(TEXT_COLOR)
        Player_Lab:setAnchorPoint(cc.p(1,0.5))
        Player_Lab:setPosition(Start_X,y)
        self:addChild(Player_Lab)
        self.PlayerNumTab={}
        Player_Lab:setVisible(false)
    
        for i,v in ipairs(PlayerData) do
            local yy=y-TEMP_Y*(number.getIntPart(i/(MAX_NUM+1)))
    
            local checkbtn =cc.ui.UICheckBoxButton.new({
                off=path .."check_1.png",
                on=path .."check_2.png",
            })
    
            local x=Start_X+X1+TEMP_X*((i-1)%MAX_NUM)
            checkbtn:setPosition(x,yy)
            self:addChild(checkbtn)
            checkbtn:onButtonClicked(function(sender)
                self:GamePlayerNumEvent(sender)
            end)
            checkbtn:setTag(TAG_PLAYER_NUM+i)
            checkbtn:setVisible(false)
            table.insert(self.PlayerNumTab,checkbtn)
    
            x=Start_X+X2+TEMP_X*((i-1)%(MAX_NUM))
    
            local str=tostring(v.Number).."人"
            local title=cc.Label:createWithSystemFont(str,TEXT_FONT, 30)
            title:setColor(TEXT_COLOR)
            title:setAnchorPoint(cc.p(0,0.5))
            title:setPosition(x,yy)
            title:setVisible(false)
            self:addChild(title)
        end
    
        self.PlayerNumTab[1]:setButtonSelected(true)
        self.PlayerNum=PlayerData[1].Number
    
        model.PlayerNum.set(self.PlayerNum)
    
        -- y=y-TEMP_Y*(number.getIntPart(#PlayerData/(MAX_NUM+1))+1)
    
        -------------------------------------------------------------------------------局数
        local jushuData=hall_model.DepletedConf.get()
        local jushuNum_Lab=cc.Label:createWithSystemFont("局数:",TEXT_FONT, 30)
        jushuNum_Lab:setColor(TEXT_COLOR)
        jushuNum_Lab:setAnchorPoint(cc.p(1,0.5))
        jushuNum_Lab:setPosition(Start_X,y)
        self:addChild(jushuNum_Lab)
        self.jushuTab={}
    
        for i,v in ipairs(jushuData) do
            local yy=y-TEMP_Y*(number.getIntPart(i/(MAX_NUM+1)))
    
            local checkbtn =cc.ui.UICheckBoxButton.new({
                off=path .."check_1.png",
                on=path .."check_2.png",
            })
    
            local x=Start_X+X1+TEMP_X*((i-1)%MAX_NUM)
            checkbtn:setPosition(x,yy)
            self:addChild(checkbtn)
            checkbtn:onButtonClicked(function(sender)
                self:GamejushuNumEvent(sender)
            end)
            checkbtn:setTag(TAG_JUSHU+i)
            table.insert(self.jushuTab,checkbtn)
    
            x=Start_X+X2+TEMP_X*((i-1)%(MAX_NUM))
            local str=v.Title.."(x"..v.DepletedNum ..")"
            local title=cc.Label:createWithSystemFont(str,TEXT_FONT, 30)
            title:setColor(TEXT_COLOR)
            title:setAnchorPoint(cc.p(0,0.5))
            title:setPosition(x,yy)
            self:addChild(title)
        end
    
        y=y-TEMP_Y*(number.getIntPart(#jushuData/(MAX_NUM+1))+1)
        self.jushuTab[1]:setButtonSelected(true)
        self.jushuNum=jushuData[1].GameRound
    
        model.GameNum.set(self.jushuNum)
    
        -------------------------------------------------------------------------------规则
        local Rule_Lab=cc.Label:createWithSystemFont("规则:",TEXT_FONT, 30)
        Rule_Lab:setColor(TEXT_COLOR)
        Rule_Lab:setAnchorPoint(cc.p(1,0.5))
        Rule_Lab:setPosition(Start_X,y)
        self:addChild(Rule_Lab)
        self.RuleTab1={}
    
        for i,v in ipairs(conf.ruleTextTab1) do
            local yy=y-TEMP_Y*(number.getIntPart(i/(MAX_NUM+1)))
    
            local checkbtn =cc.ui.UICheckBoxButton.new({
                off=path .."check_1.png",
                on=path .."check_2.png",
            })
    
            local x=Start_X+X1+TEMP_X*((i-1)%MAX_NUM)
            checkbtn:setPosition(x,yy)
            self:addChild(checkbtn)
            checkbtn:onButtonClicked(function(sender)
                self:GameRuleEvent1(sender)
            end)
            checkbtn:setTag(TAG_RULE1+i)
            table.insert(self.RuleTab1,checkbtn)
    
            x=Start_X+X2+TEMP_X*((i-1)%(MAX_NUM))
            local title=cc.Label:createWithSystemFont(v,TEXT_FONT, 30)
            title:setColor(TEXT_COLOR)
            title:setAnchorPoint(cc.p(0,0.5))
            title:setPosition(x,yy)
            self:addChild(title)
        end
    
        y=y-TEMP_Y*(number.getIntPart(#conf.ruleTextTab1/(MAX_NUM+1))+1)
    
        local Rule_Lab1=cc.Label:createWithSystemFont("亮牌:",TEXT_FONT, 30)
        Rule_Lab1:setColor(TEXT_COLOR)
        Rule_Lab1:setAnchorPoint(cc.p(1,0.5))
        Rule_Lab1:setPosition(Start_X,y)
        self:addChild(Rule_Lab1)
    
        self.RuleTab2={}
        for i,v in ipairs(conf.ruleTextTab2) do
            local yy=y-TEMP_Y*(number.getIntPart(i/(MAX_NUM+1)))
    
            local checkbtn =cc.ui.UICheckBoxButton.new({
                off=path .."check_1.png",
                on=path .."check_2.png",
            })
    
            local x=Start_X+X1+TEMP_X*((i-1)%MAX_NUM)
            checkbtn:setPosition(x,yy)
            self:addChild(checkbtn)
            checkbtn:onButtonClicked(function(sender)
                self:GameRuleEvent2(sender)
            end)
            checkbtn:setTag(TAG_RULE2+i)
            table.insert(self.RuleTab2,checkbtn)
    
            x=Start_X+X2+TEMP_X*((i-1)%(MAX_NUM))
            local title=cc.Label:createWithSystemFont(v,TEXT_FONT, 30)
            title:setColor(TEXT_COLOR)
            title:setAnchorPoint(cc.p(0,0.5))
            title:setPosition(x,yy)
            self:addChild(title)
        end
    
        for i=1,#conf.ruleTextTab1+#conf.ruleTextTab2 do
            self.rule_result[i]="0"
        end
    
        local RuleStr=hall_model.CurRule.get()
    
        self.RuleTab1[1]:setButtonSelected(true)
        self.rule_result[1]="1"
        self.RuleTab2[1]:setButtonSelected(true)
        self.rule_result[#conf.ruleTextTab1+1]="1"
    
    
    --    if RuleStr~="0" then
    --        local tRuleTab = string.toTable(RuleStr)
    --        for i=1,#conf.ruleTextTab1 do
    --            if tRuleTab[i]=="1" then
    --                self.RuleTab1[i]:setButtonSelected(true)
    --                self.rule_result[i]="1"
    --            else
    --                self.RuleTab1[i]:setButtonSelected(false)
    --                self.rule_result[i]="0"
    --            end
    --        end
    --        if tRuleTab[#conf.ruleTextTab1+1]=="1" then
    --            self.RuleTab2[1]:setButtonSelected(true)
    --            self.RuleTab2[2]:setButtonSelected(false)
    --            self.rule_result[#conf.ruleTextTab1+1]="1"
    --        else
    --            self.RuleTab2[1]:setButtonSelected(false)
    --            self.RuleTab2[2]:setButtonSelected(true)
    --            self.rule_result[#conf.ruleTextTab1+1]="0"
    --        end
    --    end
    
        model.CurRule.set(apendRule(self.rule_result))
    
    end
    
    function M:GamePlayerNumEvent(sender)
        local tag=sender.target:getTag()-TAG_PLAYER_NUM
        for i,v in ipairs(self.PlayerNumTab) do
            if i==tag then
                v:setButtonSelected(true)
            else
                v:setButtonSelected(false)
            end
        end
        local PlayerData=hall_model.PlayerNumConf.get()
        self.PlayerNum=PlayerData[tag].Number
        print("选择人数",self.PlayerNum)
    
        model.PlayerNum.set(self.PlayerNum)
    end
    
    function M:GamejushuNumEvent(sender)
        local tag=sender.target:getTag()-TAG_JUSHU
        for i,v in ipairs(self.jushuTab) do
            if i==tag then
                v:setButtonSelected(true)
            else
                v:setButtonSelected(false)
            end
        end
        local jushuData=hall_model.DepletedConf.get()
        self.jushuNum=jushuData[tag].GameRound
        print("选择局数",self.jushuNum)
    
        model.GameNum.set(self.jushuNum)
    end
    
    function M:GameRuleEvent1(sender)
        local tag=sender.target:getTag()-TAG_RULE1
        for i=1,#self.RuleTab1 do
            if i==tag then
                self.RuleTab1[i]:setButtonSelected(true)
                self.rule_result[i]="1"
            else
                self.RuleTab1[i]:setButtonSelected(false)
                self.rule_result[i]="0"
            end
        end
    
        print("规则",self:getRuleResult())
        model.CurRule.set(apendRule(self.rule_result))
    end
    
    function M:GameRuleEvent2(sender)
        local tag=sender.target:getTag()-TAG_RULE2
        local IsSelect=sender.target:isButtonSelected()
        for i=1,#self.RuleTab2 do
            if i==tag then
                self.RuleTab2[i]:setButtonSelected(true)
            else
                self.RuleTab2[i]:setButtonSelected(false)
            end
        end
        if tag==2 then
            self.rule_result[#self.RuleTab1+1]="0"
        elseif tag==1 then
            self.rule_result[#self.RuleTab1+1]="1"
        end
    
        print("规则",self:getRuleResult())
        model.CurRule.set(apendRule(self.rule_result))
    end
    
    --获取人数
    function M:getPlayerNum()
        return self.PlayerNum
    end
    
    --获取局数
    function M:getJushu()
        return self.jushuNum
    end
    
    --获取规则
    function M:getRuleResult()
        local ruleStr=apendRule(self.rule_result)
        return ruleStr
    end
    
    return M
    
    
    
    
    
    
    






